<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for X.509v1 Certificate 'x509.js'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/crypto-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>

<script type="text/javascript">
$(document).ready(function(){

// **** DATA **********

// from https://github.com/kjur/jsrsasign/issues/253
var cert1pem = (function() {/*
-----BEGIN CERTIFICATE-----
MIIDJzCCAg8CAQswDQYJKoZIhvcNAQELBQAwbTELMAkGA1UEBhMCVVMxDjAMBgNV
BAgTBVRleGFzMQ8wDQYDVQQHEwZBdXN0aW4xDTALBgNVBAoTBERFTU8xFzAVBgNV
BAsTDkRFTU8gQ29ycG9yYXRlMRUwEwYDVQQDEwxERU1PIFJvb3QgQ0EwHhcNMTcw
NDExMTY0NjE5WhcNMjcwMTA5MTY0NjE5WjBGMUQwQgYDVQQDDDs5eTNnNXEubWVz
c2FnaW5nLmZyYTAyLTMudGVzdC5pbnRlcm5ldG9mdGhpbmdzLmlibWNsb3VkLmNv
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANrwaPyG3KshIzr7Kvo9
uzQZO675VkS+WO9JKUiaYYaYbMPDIZqEvnYheKPlXDVPTxViE7Zat0wGcFI8AguM
ZzYUIWfeJCXUFJXORGVwWuSfYRrRabf9ReAV7kYdeR8kfzCXFT+6nsgbRqYMCi2q
nRaGCs3+WOgOsVa71VerngkRpVpFjv15V93bqFFkUKcA08Q5eP5DzgXxfX/kgXWK
Gjb6VsbADhaZzeM/jCrP3kvYRfofHCzKbZOJGrmvd6il+a5CKOL00IHUktN7shhp
sMqfPyHWgWy6Ik+pA9rGut5XzGeLoRZiZnRudWTcQa2c2POH5fyxN6edj2CXWYY9
5zUCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEATOfLas14rU9Lrq2zNj9iHpuMXKBW
XCoFduttNA5VGgZYFHy1NrgYleDISRCjCk9lXQsjV/m7VnBTrI3ncwYvVdS+n2Dv
UN9zcm8+SzyVDBzXVl+kXOUXy5rHGagxqT3M1cij3NAxosufzXn61fSRCaVgezEF
7crQjMhYPepbYCvsv6NGzdA2D3+uAfb4hq3J8y1qHrNxBcgKogeGWMs0/I827YBB
vAFw1qhcoTZb+EymNNl5xstmby25fd3jVVOwa5FbrImCdCglNbq+7UC4ZgCd9F7F
0MMxg4N7v8ruoVffaUwKKNtNykA/sKyrtOhEdTbbRNToSOjD99Adc4rhoQ==
-----END CERTIFICATE-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

var cert1hex = pemtohex(cert1pem);

// **** TEST **********
test("X509v1 field test", function() {
  var x = new X509();
  x.readCertPEM(cert1pem);
  equal(x.version, 1, "version");
  equal(x.getVersion(), 1, "getVersion()");
  equal(x.getSerialNumberHex(), "0b", "sn = 0b");
  equal(x.getSignatureAlgorithmField(), "SHA256withRSA", "alg = SHA256withRSA");
  equal(x.getIssuerHex().substr(0, 48), "306d310b3009060355040613025553310e300c0603550408", "issuer hex(48)");
  equal(x.getIssuerString(), "/C=US/ST=Texas/L=Austin/O=DEMO/OU=DEMO Corporate/CN=DEMO Root CA", "issuer");
  equal(x.getSubjectHex().substr(0, 48), "30463144304206035504030c3b3979336735712e6d657373", "subject hex(48)");
  equal(x.getSubjectString(), "/CN=9y3g5q.messaging.fra02-3.test.internetofthings.ibmcloud.com", "subject");
  equal(x.getNotBefore(), "170411164619Z", "not before");
  equal(x.getNotAfter(),  "270109164619Z", "not after");
  equal(x.getPublicKeyHex().substr(0, 26),  "30820122300d06092a864886f7", "public key hex");
  equal(x.getPublicKey() instanceof RSAKey, true, "public key rsa");
  equal(hextoposhex(x.getPublicKey().n.toString(16)).substr(0, 14), "00daf068fc86dc", "public key rsa.n daf0..");
  equal(x.getPublicKey().e.toString(16), "10001", "public key rsa.e 10001");
});

});
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>

<p>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-x509.html">x509</a> | 
<a href="qunit-do-x509-ext.html">x509-ext</a> | 
<a href="qunit-do-x509-key.html">x509-key</a> | 
<a href="qunit-do-x509-kid.html">x509-kid</a> | 
<a href="qunit-do-x509-getinfo.html">x509-getinfo</a> | 
<a href="qunit-do-x509-v1.html">x509-v1</a> | 
</p>

</body>
<center><p>&copy; 2010-2017 Kenji Urushima</p></center>
</html>

